'use strict';
const entry = require('../src/model/endpoints');

exports.entry = entry;

const proxyEntry = {
    WEAPP_SSOSEVER_API: '/sso',
    WEAPP_PUBLIC_API: '/public',
    WEAPP_HEALTH_API: '/api'
};

const proxyMapper = ({ item, value }) => {
    return {
        target: entry[item],
        context: [value],
        changeOrigin: true,
        secure: false,
        cookieDomainRewrite: {
            '*': ''
        }
    };
};

const proxy = Object.keys(proxyEntry).map(item => {
    let value = proxyEntry[item];
    return {
        ...proxyMapper({ item, value }),
        pathRewrite: {
            [`^${value}`]: ''
        }
    };
});

module.exports = {
    env: {
        NODE_ENV: '"development"',
        QINIU_REMOTE: '"https://images.doctorwork.com/lifestream"'
    },
    weapp: {},
    h5: {
        devServer: {
            proxy: [
                ...proxy,
                proxyMapper({ item: entry.GRAPHQL_PATH, value: '/graphql' })
            ]
        }
    }
};
